//
//  T1_5_CCell.swift
//  Pods
//
//  Created by eme on 2017/4/10.
//
//

/*
 owner:cy
 update:2017年04月10日18:16:02
 info: 图文类 cell
 VC :  HomePageVc
 */
import UIKit
import RxSwift

class T1_5_CCell: UICollectionViewCell {
    
    @IBOutlet weak var small_left_ImgV: UIImageView!
    
    @IBOutlet weak var small_right_ImgV: UIImageView!
    
    
    var didSelectItem_Closure:((_ item:T1ListModel) -> Void)?
    
    var listItem:[T1ListModel]?{
        didSet{
            if let listItem = self.listItem {
                for (index , item ) in listItem.enumerated(){
                    if index == 0 {
                        self.small_left_ImgV.setUrlImage(item.urlid.getUrlStr(), placeholderImage: "product-placeholder")
                    }else if index == 1{
                        self.small_right_ImgV.setUrlImage(item.urlid.getUrlStr(), placeholderImage: "product-placeholder")
                    }
                }
            }
        }
    }
    override func awakeFromNib() {
        self.small_left_ImgV.image = UIImage(named: "product-placeholder", in: RobbCore.bundle, compatibleWith: nil)
        self.small_right_ImgV.image = UIImage(named: "product-placeholder", in: RobbCore.bundle, compatibleWith: nil)
        
        self.small_left_ImgV.isUserInteractionEnabled = true
        self.small_right_ImgV.isUserInteractionEnabled = true
        
        self.small_left_ImgV.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap(gestureReconizer:))))
        self.small_right_ImgV.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap(gestureReconizer:))))
    }
    
}
extension T1_5_CCell{
    func tap(gestureReconizer: UITapGestureRecognizer) {
        if gestureReconizer.state != UIGestureRecognizerState.ended {
            return
        }
        if gestureReconizer.view == self.small_left_ImgV , self.listItem!.count > 0 {
            self.didSelectItem_Closure?(self.listItem![0])
        }else if gestureReconizer.view == self.small_right_ImgV , self.listItem!.count > 1 {
            self.didSelectItem_Closure?(self.listItem![1])
        }
    }
}
